<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="/static/js/include.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>MBIT测试</title>
<script type="text/javascript">
	function getNextPage(){
		//如果用户答完试题就显示报告页面，否则显示下一道试题
		var totalNum = {{ request.session.totalNum }}
		var qno = $("#qno").val();
		if(parseInt(totalNum-1) == parseInt(qno)){
			location.href = "/report";
		}else{
			var url = "/question?qno="+qno;
			$.get(url,function(data,status){
			    $("#content").html(data);
			});
		}
	}
	
	function optionChange(){
		//var csrfmiddlewaretoken = $("input[name='csrfmiddlewaretoken']").val();
		var question_id = $("#question_id").val();
		var option_id = $("input[name='option']:checked").val()
		$.post("/saveAnswer/",
			{
				//csrfmiddlewaretoken:csrfmiddlewaretoken,
				question_id:question_id,
				option_id:option_id
			},
			function(data,status){
				if(status="success"){
					//显示下一个页面
					getNextPage();
				}else{
					alert("fail");
				}
			});
	}
</script>
</head>
<body>
	
	<div id="content" class="main">
		<input type="hidden" id="question_id" value="{{question.id}}">
		<input type="hidden" id="qno" value="{{qno}}">
		<p class="title">{{question.content}}</p>
		{% for option in options %}
			<p class="hint">
				<input type="radio" name="option" onclick="optionChange()" value="{{option.id}}"/>{{option.serialno}}、{{option.content}}
			</p>
		{% endfor %}
	</div>
</body>
</html>
